import React, { useEffect, useState } from 'react'
import { Modal, Form, Input, Select } from 'antd';
import { AddTag, GetUserTag } from '@/apis/user';

const { Option } = Select;

type Props = {
    visiable: boolean
    close: (state: boolean) => void
}


const AddUserCate = ({ visiable, close }: Props) => {
    const [form] = Form.useForm()
    const [list, setList] = useState<any>([])

    useEffect(() => { getAll() }, [])

    // 获取标签
    const getAll = async () => {
        const res: any = await GetUserTag({ parent: 0 })
        setList(res.data)
    }

    const handleOk = async () => {
        const value = form.getFieldsValue()
        console.log(value);
        const res = await AddTag({ ...value, parent: 0 })
        console.log(res);
        close(false)

    }
    const handleCancel = () => { close(false) }

    return (
        <Modal title="添加标签" open={visiable} destroyOnClose={true} onOk={handleOk} onCancel={handleCancel} width={700}>
            <Form preserve={false} form={form} labelCol={{ span: 4 }}>
                <Form.Item label='分类名称' name='name' rules={[{ required: true }]}>
                    <Input />
                </Form.Item>
            </Form>
        </Modal>
    )
}

export default AddUserCate